//
//  YYEExampleCell1.m
//  YuYingEDU
//
//  Created by zl on 2018/3/15.
//  Copyright © 2018年 胡波. All rights reserved.
//

#import "YYEExampleCell1.h"

@interface YYEExampleCell1 ()<UITextViewDelegate>



@end

@implementation YYEExampleCell1

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.contentView.backgroundColor = GeneralBackColor;

        
        //输入框
        UITextView *textView = [[UITextView alloc] init];
        textView.delegate = self;
        textView.layer.cornerRadius = 2.f;
        textView.layer.masksToBounds = YES;
        textView.layer.borderWidth = 1.f;
        textView.layer.borderColor = [[UIColor colorWithHexString:@"#999999"] CGColor];
        textView.font = [UIFont systemFontOfSize:14.f];
//        textView.backgroundColor = KWhiteColor;
        [self.contentView addSubview:textView];
        self.textView = textView;
        
        //默认提示标签
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(3, 6, 200, 20)];
        label.font = [UIFont systemFontOfSize:14.f];
        label.textColor = [UIColor colorWithHexString:@"#c8c8c8"];
        [textView addSubview:label];
        self.label = label;
        label.text = @"请填写答案";
        
    }
    
    return self;
}

- (void)setModel:(ChoiceModel *)model
{
    _model = model;
    
    if (self.questionType.integerValue == 4) {
        
        self.textView.frame = CGRectMake(25, 0, kScreenWidth-50, 35);
        self.label.frame = CGRectMake(3, (self.textView.jc_height-20)/2, 200, 20);

    }
    else {
        self.textView.frame = CGRectMake(25, 0, kScreenWidth-50, 150);
        self.label.frame = CGRectMake(3, 6, 200, 20);

    }
    
    model.cellHeight = self.textView.jc_height+10;
    
    self.textView.text = model.content;
    
    if (model.content) {
        self.label.hidden = YES;
    }
    else {
        self.label.hidden = NO;

    }
    
}

- (void)textViewDidChange:(UITextView *)textView
{
    _label.hidden = [textView.text length] == 0 ? NO : YES;
    _model.content = textView.text;
}

@end
